//
//  BiCarSaleParser.m
//  TrunkIndustryManageSystem
//
//  Created by 李璐西 on 15-4-6.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiCarSaleParser.h"
#import "JSONKit.h"
#import "BiCarSaleCheckEntity.h"
#import "BiCustomerInfo.h"
#import "BiCarSaleContractEntity.h"
#import "BiCarSaleGpsEntity.h"
#import "MJExtension.h"
@implementation BiCarSaleParser

SINGLE_INSTANCE_IMPLEMENTION(BiCarSaleParser)

+ (NSDictionary*)parserCarSaleCheckListEntity:(NSString*)jsonStr
{
    NSMutableArray * array = [NSMutableArray array];

    NSDictionary *jsonDict = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
        
    id  data = jsonDict[@"data"];
        
    if ([data isKindOfClass:[NSString class]]||[data isKindOfClass:[NSNull class]]) {
        
    }else if ([data isKindOfClass:[NSArray class]]){
        
        NSArray *dataArr = (NSArray *)data;
        
        if (0 == dataArr.count) {
                

        }else{
                
            for (NSInteger i = 0; i < dataArr.count; i++) {
                    
                NSDictionary * dataDic = dataArr[i];
                    
                BiCarSaleCheckEntity * entity = [[BiCarSaleCheckEntity alloc] init];
                    
                entity.destination = GET_NOT_NULL_STRING(dataDic[@"destination"]);
                entity.fee = GET_NOT_NULL_STRING(dataDic[@"fee"]);
                entity.gooffTime = GET_NOT_NULL_STRING(dataDic[@"gooffTime"]);
                entity.e_id = GET_NOT_NULL_STRING(dataDic[@"id"]);
                entity.kilometre = GET_NOT_NULL_STRING(dataDic[@"kilometre"]);
                entity.licensePlate = GET_NOT_NULL_STRING(dataDic[@"licensePlate"]);
                entity.participant = GET_NOT_NULL_STRING(dataDic[@"participant"]);
                entity.remark = GET_NOT_NULL_STRING(dataDic[@"remark"]);
                entity.returnTime = GET_NOT_NULL_STRING(dataDic[@"returnTime"]);
                entity.systemNumber = GET_NOT_NULL_STRING(dataDic[@"systemNumber"]);
                entity.totalNum = GET_NOT_NULL_STRING(dataDic[@"totalNum"]);
                entity.useCarType = GET_NOT_NULL_STRING(dataDic[@"useCarType"]);
                entity.userApplyId = GET_NOT_NULL_STRING(dataDic[@"userApplyId"]);
                entity.userApplyName = GET_NOT_NULL_STRING(dataDic[@"userApplyName"]);
                entity.xingxiaoRejectReason = GET_NOT_NULL_STRING(dataDic[@"xingxiaoRejectReason"]);
                entity.startPlace = GET_NOT_NULL_STRING(dataDic[@"startPlace"]);
                entity.isExecuted = GET_NOT_NULL_STRING(dataDic[@"isExecuted"]);
                
                entity.trueStartTime = GET_NOT_NULL_STRING(dataDic[@"trueStartTime"]);
                entity.trueEndTime = GET_NOT_NULL_STRING(dataDic[@"trueEndTime"]);
                entity.trueTotalTime = GET_NOT_NULL_STRING(dataDic[@"trueTotalTime"]);
                entity.trueTotalDistance = GET_NOT_NULL_STRING(dataDic[@"trueTotalDistance"]);
                
                [array addObject:entity];
            }
        }
    }
        
  return [NSDictionary dictionaryWithObjectsAndKeys:jsonDict[@"response_status"],@"response_status",jsonDict[@"result_info"],@"result_info",array,@"data", nil];;
}


+ (NSDictionary*)parserCarSaleContractListEntity:(NSString*)jsonStr{

    NSMutableArray * array = [NSMutableArray array];
    
    NSDictionary *jsonDict = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    id  data = jsonDict[@"data"];
    
    if ([data isKindOfClass:[NSString class]]||[data isKindOfClass:[NSNull class]]) {
        
    }else if ([data isKindOfClass:[NSArray class]]){
        
        NSArray *dataArr = (NSArray *)data;
        
        if (0 == dataArr.count) {
            
        }else{
            for (NSInteger i = 0; i < dataArr.count; i++) {
                
                NSDictionary * dataDic = dataArr[i];
                
                
                
                BiCarSaleContractEntity * entity = [[BiCarSaleContractEntity alloc] init];
                
                if ([dataDic[@"car"] isKindOfClass:[NSDictionary class]]) {
                    
                    entity.car_brand = GET_NOT_NULL_STRING(dataDic[@"car"][@"brand"]);
                    entity.car_carCategoryName = GET_NOT_NULL_STRING(dataDic[@"car"][@"carCategoryName"]);
                    entity.car_carSeries = GET_NOT_NULL_STRING(dataDic[@"car"][@"carSeries"]);
                    entity.car_categoryId = GET_NOT_NULL_STRING(dataDic[@"car"][@"categoryId"]);
                    entity.car_id = GET_NOT_NULL_STRING(dataDic[@"car"][@"id"]);
                    entity.car_vin = GET_NOT_NULL_STRING(dataDic[@"car"][@"vin"]);
                    
                }else{
                
                    entity.car_brand = @"";
                    entity.car_carCategoryName = @"";
                    entity.car_carSeries = @"";
                    entity.car_categoryId = @"";
                    entity.car_id = @"";
                    entity.car_vin = @"";
                }
                
                if ([dataDic[@"orderTemplate"] isKindOfClass:[NSDictionary class]]) {
                    entity.car_brand = GET_NOT_NULL_STRING(dataDic[@"orderTemplate"][@"brand"]);;
                    entity.car_carSeries = GET_NOT_NULL_STRING(dataDic[@"orderTemplate"][@"carSeries"]);
                    entity.car_id = GET_NOT_NULL_STRING(dataDic[@"orderTemplate"][@"id"]);
                }
                
                if ([dataDic[@"carOrder"] isKindOfClass:[NSDictionary class]]) {
                    
                    id temp = dataDic[@"carOrder"][@"electronicContractImg"];
                    if ([temp isKindOfClass:[NSArray class]]) {
                        
                        entity.carOrder_ConnectImgArr = dataDic[@"carOrder"][@"electronicContractImg"];
                    }else if ([temp isKindOfClass:[NSString class]]){
                    
                        entity.carOrder_electronicContractImg = dataDic[@"carOrder"][@"electronicContractImg"];
                    }
                    
                    
                    
                    entity.carOrder_connectCarTime = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"connectCarTime"]);
                    entity.carOrder_createTime = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"createTime"]);
                   
                    entity.carOrder_giftDetail = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"giftDetail"]);
                    entity.carOrder_giftMoney = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"giftMoney"]);
                    entity.carOrder_id = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"id"]);
                    entity.carOrder_orderTime = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"orderTime"]);
                    entity.carOrder_orderType = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"orderType"]);
                    entity.carOrder_salemanId = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"salemanId"]);
                    entity.carOrder_sellPrice = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"sellPrice"]);
                    entity.carOrder_specialDemand = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"specialDemand"]);
                    entity.carOrder_subscription = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"subscription"]);
                    
                    entity.carOrder_articleConnectImg = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"articleConnectImg"]);;
                    entity.carOrder_balanceMoney = GET_NUM_FLOAT_VALUE(dataDic[@"carOrder"][@"balanceMoney"]);;
                    entity.carOrder_carConnectImg = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"carConnectImg"]);;
                    entity.carOrder_carId = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"carId"]);;
                    entity.carOrder_connectPerson = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"connectPerson"]);;
                    entity.carOrder_connectTime = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"connectTime"]);;
                    entity.carOrder_discountMoney = GET_NUM_FLOAT_VALUE(dataDic[@"carOrder"][@"discountMoney"]);;
                    entity.carOrder_groupPhotoImg = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"groupPhotoImg"]);;
                    entity.carOrder_memberId = GET_NOT_NULL_STRING(dataDic[@"carOrder"][@"memberId"]);;
                    entity.carOrder_shishouMoney = GET_NUM_FLOAT_VALUE(dataDic[@"carOrder"][@"shishouMoney"]);;
                    entity.carOrder_yingshouMoney = GET_NUM_FLOAT_VALUE(dataDic[@"carOrder"][@"yingshouMoney"]);;
                    
                }else{
                
                    //合同
                    entity.carOrder_connectCarTime = @"";
                    entity.carOrder_createTime = @"";
                    entity.carOrder_electronicContractImg = nil;
                    entity.carOrder_giftDetail = @"";
                    entity.carOrder_giftMoney = @"";
                    entity.carOrder_id = @"";
                    entity.carOrder_orderTime = @"";
                    entity.carOrder_orderType = @"";
                    entity.carOrder_salemanId = @"";
                    entity.carOrder_sellPrice = @"";
                    entity.carOrder_specialDemand = @"";
                    entity.carOrder_subscription = @"";
                    
                    //交接
                    entity.carOrder_articleConnectImg = @"";
                    entity.carOrder_balanceMoney = 0.0;
                    entity.carOrder_carConnectImg = @"";
                    entity.carOrder_carId = @"";
                    entity.carOrder_connectPerson = @"";
                    entity.carOrder_connectTime = @"";
                    entity.carOrder_discountMoney = 0.0;
                    entity.carOrder_groupPhotoImg = @"";
                    entity.carOrder_memberId = @"";
                    entity.carOrder_shishouMoney = 0.0;
                    entity.carOrder_yingshouMoney = 0.0;
                    
                }
                
                if ([dataDic[@"member"] isKindOfClass:[NSDictionary class]]){
                    entity.member_id = GET_NOT_NULL_STRING(dataDic[@"member"][@"id"]);
                    entity.member_name = GET_NOT_NULL_STRING(dataDic[@"member"][@"name"]);
                    entity.member_address = GET_NOT_NULL_STRING(dataDic[@"member"][@"address"]);
                    entity.member_phone = GET_NOT_NULL_STRING(dataDic[@"member"][@"phone"]);
                    entity.member_nation = GET_NOT_NULL_STRING(dataDic[@"member"][@"nation"]);
                }else{
                    entity.member_id = @"";
                    entity.member_name = @"";
                    entity.member_phone = @"";
                    entity.member_address = @"";
                    entity.member_nation = @"";
                }
                
                if ([dataDic[@"saleman"] isKindOfClass:[NSDictionary class]]){
                    entity.saleman_id = GET_NOT_NULL_STRING(dataDic[@"saleman"][@"id"]);
                    entity.saleman_name = GET_NOT_NULL_STRING(dataDic[@"saleman"][@"name"]);
                }else{
                    entity.saleman_id = @"";
                    entity.saleman_name = @"";
                }
                
                if ([dataDic[@"connectUser"] isKindOfClass:[NSDictionary class]]){
                    entity.connectUser_id = GET_NOT_NULL_STRING(dataDic[@"connectUser"][@"id"]);
                    entity.connectUser_name = GET_NOT_NULL_STRING(dataDic[@"connectUser"][@"name"]);
                }else{
                    entity.connectUser_id = @"";
                    entity.connectUser_name = @"";
                }
                
                [array addObject:entity];

            }
        }
    }
    
    return [NSDictionary dictionaryWithObjectsAndKeys:jsonDict[@"response_status"],@"response_status",jsonDict[@"result_info"],@"result_info",array,@"data", nil];;
}


+ (NSDictionary *)parserCarSaleApplyEntity:(NSString*)jsonStr
{
    
    NSDictionary * jsonDic = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:jsonDic];

    return dict;
}


+ (NSDictionary *)parserCommonDict:(NSString*)jsonStr
{
    
    NSDictionary * jsonDic = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithDictionary:jsonDic];
    
    return dict;
}


+ (NSDictionary *)parserCarSaleGetCustomerListEntity:(NSString*)jsonStr
{

    NSMutableArray * array = [NSMutableArray array];
    
    NSDictionary *jsonDict = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    id  data = jsonDict[@"data"];
    
    if ([data isKindOfClass:[NSString class]]||[data isKindOfClass:[NSNull class]]) {
        
    }else if ([data isKindOfClass:[NSArray class]]){
        
        NSArray *dataArr = (NSArray *)data;
        
        if (0 == dataArr.count) {

        }else{
            
            for (NSInteger i = 0; i < dataArr.count; i++) {
                
                NSDictionary * dataDic = dataArr[i];
                
                BiCustomerInfo * entity = [[BiCustomerInfo alloc] init];
                entity.collectAddress = GET_NOT_NULL_STRING(dataDic[@"collectAddress"]);
                entity.collectTime = GET_NOT_NULL_STRING(dataDic[@"collectTime"]);
                entity.createTime = GET_NOT_NULL_STRING(dataDic[@"createTime"]);
                entity.customerCarphoto = GET_NOT_NULL_STRING(dataDic[@"customerCarphoto"]);
                entity.customerId = GET_NOT_NULL_STRING(dataDic[@"customerId"]);
                entity.customerName = GET_NOT_NULL_STRING(dataDic[@"customerName"]);
                entity.customerPhone = GET_NOT_NULL_STRING(dataDic[@"customerPhone"]);
                entity.distance = GET_NOT_NULL_STRING(dataDic[@"distance"]);
                
                entity.lineDistance = GET_NOT_NULL_STRING(dataDic[@"lineDistance"]);
                entity.latitude = GET_NOT_NULL_STRING(dataDic[@"latitude"]);
                entity.longitude = GET_NOT_NULL_STRING(dataDic[@"longitude"]);
                
                entity.e_id = GET_NOT_NULL_STRING(dataDic[@"id"]);
                entity.isOwer = GET_NOT_NULL_STRING(dataDic[@"isOwer"]);
                entity.messageColletPersonId = GET_NOT_NULL_STRING(dataDic[@"messageColletPersonId"]);
                entity.messageColletPersonName = GET_NOT_NULL_STRING(dataDic[@"messageColletPersonName"]);
                entity.restaurantPhoto = GET_NOT_NULL_STRING(dataDic[@"restaurantPhoto"]);
                entity.sellId = GET_NOT_NULL_STRING(dataDic[@"sellId"]);
                entity.visitorCustomerPhoto = GET_NOT_NULL_STRING(dataDic[@"visitorCustomerPhoto"]);
                [array addObject:entity];
            }
        }
    }


    return [NSDictionary dictionaryWithObjectsAndKeys:jsonDict[@"response_status"],@"response_status",jsonDict[@"result_info"],@"result_info",array,@"data", nil];
}

//行销执行之获取gps信息列表
+ (NSDictionary *)parserGetGpsListEntity:(NSString*)jsonStr{

    NSDictionary * jsonDic = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
    
    NSMutableArray * array = [NSMutableArray array];
    
    id data = jsonDic[@"data"];
    
    if ([data isKindOfClass:[NSArray class]]) {
        
        NSArray * dataArr = (NSArray *)data;
        
       [array addObjectsFromArray:[BiCarSaleGpsEntity objectArrayWithKeyValuesArray:dataArr]];
        
    }
    return [NSDictionary dictionaryWithObjectsAndKeys:jsonDic[@"response_status"],@"response_status",jsonDic[@"result_info"],@"result_info",array,@"data", nil];
}

@end
